﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace YSGetLatest.DataObjects
{
	/// <summary>
	/// Contains information about project to get latest.
	/// </summary>
	[Serializable]
	public class Folder : BaseDataObject
	{
		#region Fields

		private bool enabled_;
		private bool enabledSaved_;
		private string name_;
		private string nameSaved_;
		[NonSerialized]
		private bool isSelected_;
		[NonSerialized]
		private bool isFailed_;
		#endregion

		#region Properties

		/// <summary>
		/// Get latest for this project.
		/// </summary>
		public bool Enabled
		{
			get
			{
				return enabled_;
			}
			set
			{
				enabled_ = value;
				SetPropertyChanged("Enabled");
			}
		}

		/// <summary>
		/// Path to project on disk.
		/// </summary>
		public string Name
		{
			get
			{
				return name_;
			}
			set
			{
				name_ = value;
				SetPropertyChanged("Name");
			}
		}

		/// <summary>
		/// Gets or sets a value that indicates whether a Folder is selected.
		/// </summary>
		/// <value>
		/// true if the item is selected; otherwise, false. The default is false.
		/// </value>
		[XmlIgnore]
		public bool IsSelected
		{
			get
			{
				return isSelected_;
			}
			set
			{
				isSelected_ = value;
				SetPropertyChanged("IsSelected");
			}
		}

		/// <summary>
		/// Gets or sets a value that indicates whether Get Latest failed for a folder. 
		/// </summary>
		[XmlIgnore]
		public bool IsFailed
		{
			get
			{
				return isFailed_;
			}
			set
			{
				isFailed_ = value;
				SetPropertyChanged("IsFailed");
			}
		}
		#endregion

		#region BaseDataObject Methods

		/// <summary>
		/// Saves data members.
		/// </summary>
		protected override void Save()
		{
			enabledSaved_ = Enabled;
			nameSaved_ = Name;
		}

		/// <summary>
		/// Restores data members.
		/// </summary>
		protected override void Restore()
		{
			Enabled = enabledSaved_;
			Name = nameSaved_;
		}
		#endregion

		#region Methods

		/// <summary>
		/// Returns the text representation of the instance.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			var buffer = new StringBuilder();

			buffer.AppendFormat("{0}:", GetType().Name);
			buffer.AppendFormat(" Name: \"{0}\"", Name);
			buffer.AppendFormat(", Enabled: {0}", Enabled);
			buffer.AppendFormat(", IsSelected: {0}", IsSelected);
			buffer.AppendFormat(", IsFailed: {0}", IsFailed);

			return buffer.ToString();
		}
		#endregion
	}
}
